﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TireBias.Models.BIASPLANModel.BIASPLAN_DS>" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   Header_line_barcode</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style type="text/css">
      #txtInputA, #txtInputB
      {
         font-size: 1em;
         height: 2em;
         line-height: 2.5em;
         width: 90%;
      }
      .nomat
      {
         color:Red !important;
      }
   </style>
   <table class="shadow" style="margin-left: 5%; width: 94%">
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._Text))
         {%>
      <tr>
         <td colspan="2" class="cell" style="font-size: x-large; margin-left: 5%; line-height: 35px;
            padding: 5px; background-color: #C38DEC; color:White">
           <%= Model._Text%>
         </td>
      </tr>
      <%} %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            DATE-SEQ<br />
            <span class="fontTh">ล็อตที่ผลิต</span>
         </td>
         <td class="cell" id="seqDT">
       <h3>   <%= Model._Plandt %>-<%=Model._Itemno%></h3>  
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            SIZE<br />
            <span class="fontTh">ขนาดผ้าใบ</span>
         </td>
         <td class="cell" id="Td1">
         <h3> <%= Model._Size %></h3>  
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            FORMING
            <br />
            <span class="fontTh">เครื่องที่สร้าง</span>
         </td>
         <td class="cell" id="Td2">
        <h3>   <%= Model._Forming %></h3> 
         </td>
      </tr>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P1))
         { %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            P1
            <br />
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 1 (มม.)</span>
         </td>
         <td class="cell" id="Td3">
     <h3>  <%= Model._P1%></h3>     
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P2))
         { %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            P2
            <br />
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 2 (มม.)</span>
         </td>
         <td class="cell" id="Td4">
        <h3>   <%= Model._P2%></h3> 
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P3))
         { %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            P3
            <br />
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 3 (มม.)</span>
         </td>
         <td class="cell" id="Td5">
           <h3> <%= Model._P3%></h3>
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P4))
         { %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            P4
            <br />
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 4 (มม.)</span>
         </td>
         <td class="cell" id="Td6">
          <h3> <%= Model._P4%></h3> 
         </td>
      </tr>
      <% } %>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            Topped Cord
            <br />
            <span class="fontTh">ผ้าใบ</span>
         </td>
         <td class="cell" id="Td7">
         <h3>  <%= Model._Topcrdcd%></h3> 
         </td>
      </tr>
      <tr class="rowa">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Topped Cord B
            <br />
            <span class="fontTh">ผ้าใบ B</span>
         </td>
         <td class="cell">
            <input type="password" id="txtInputB" cols="B" chk=""  value=""   onkeydown="checkEnter($(this));"  />
         </td>
      </tr>
      <tr class="rowa">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Topped Cord A
            <br />
            <span class="fontTh">ผ้าใบ A</span>
         </td>
         <td class="cell">
            <input type="password" id="txtInputA" cols="A" chk="" value=""    onkeydown="checkEnter($(this));"  />
         </td>
      </tr>
      
   </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <section class="featured">
 <div class="content-wrapper" style="height:40px">
            <hgroup class="title float-left">
            <h1>Bias Head Computer</h1>
                <h2  style="padding-left:55px;">BIAS NO.<%= TireBias.Models.SessionBag.Current.biasno %></h2>      
              
            </hgroup> 
             <hgroup class="title float-right">
                <h3>
         Name :
         <% if (Request.IsAuthenticated)
            { %>
         <%:  User.Identity.Name %>
         <% } %></h3>
            </hgroup>   
 </div>
 </section>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
     <div class="float-left" style="margin-left: 50px;">
          <input type="button" id="back" value="BACK" class="btnFooter"  
              style="height: 75px;  width: 350px;" />
        
      </div>
   <div id="dialog-a" title="Topped Cord A is expired">
      <div class="cap cell">
         ITEM</div>
      <div class="desc cell">
         A</div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Topped Cord<br />
         <span class="fontTh">ผ้าใบ</span></div>
      <div class="desc cell" id="dcode" style="height: 50px;">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Tire Cord Lot<br />
         <span class="fontTh">ล็อตที่ผลิต</span></div>
      <div class="desc cell" id="dLot" style="height: 50px;">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Expired Date<br />
         <span class="fontTh">วันที่หมดอายุ</span></div>
      <div class="desc cell" style="color: Red; height: 50px;" id="dexp">
      </div>
     <div style="clear: left" />
     
      <div class="cap cell">
         Length<br />
         <span class="fontTh">ความยาว</span></div>
      <div class="desc cell" id="dLen" style="height: 50px;">
      </div>

      <div style="clear: left">
      </div>
      <div class="cap cell">
         Roll no.<br />
         <span class="fontTh">รถคันที่</span></div>
      <div class="desc cell" id="rollno" style="height: 50px;">
      </div>
      <input type="hidden" value="" id="reaExp" />
   </div>
   <%--//************ dialog *******************//--%>
   <div id="dialog-b" title="Use Tire Cord">
      <table style="width: 98%" class="fontTB">
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px; width: 30%">
               Emp code</td>
            <td class="cell">
               <input type="text" id="txtempnm" style="width: 75%" maxlength="6" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Password
            </td>
            <td class="cell">
               <input type="password" id="txtpass" style="width: 75%" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Short Text
            </td>
            <td class="cell">
               <input type="text" id="txtshort" style="width: 75%" maxlength="30" />
            </td>
         </tr>
      </table>
   </div>
   <div id="dialog-c" title="">
      <table width="95%">
         <tr class="head shadow" style="height:35px">
            <td class="cell" style="width: 40%">
               ITEM
            </td>
            <td class="cell">
               A
            </td>
            <td class="cell">
               B
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell" style="text-align: left;">
               Topped Cord<br />
               <span class="fontTh">ผ้าใบ</span>
            </td>
            <td  class="cell" id="dCodeA">
            </td>
            <td class="cell" id="dCodeB">
            </td>
         </tr>
         <tr class="rowa cell">
            <td style="text-align: left;" class="head cell">
               Tire Cord Lot
               <br />
               <span class="fontTh">ล็อคที่ผลิต</span>
            </td>
            <td id="dLotA" class="cell">
            </td>
            <td id="dLotB" class="cell">
            </td>
         </tr>
         <tr class="rowa cell" >
            <td style="text-align: left;" class="head cell">
               Expired Date
               <br />
               <span class="fontTh">วันที่หมดอายุ</span>
            </td>
            <td id="dExpA" class="cell">
            </td>
            <td id="dExpB" class="cell">
               
            </td>
         </tr>
          
         <tr class="rowa">
            <td style="text-align: left;" class="head cell">
              Rollno
               <br />
                ม้วนที่
            </td>
            <td id="dRollA" class="cell">
            </td>
            <td id="dRollB" class="cell">
               
            </td>
         </tr>
      </table>
      <input type="hidden" value="" id="txtreaMat" />
   </div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">
    <% if (false)
      { %>
   <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
   <% } %>
   <script type="text/javascript">
       function checkEnter(obj) {
           if (event.keyCode == 13) {
               var nm = (obj.attr("id"));             
               if (nm == "txtInputA") $("#txtInputB").focus();
               if (nm == "txtInputB") $("#txtInputA").focus();
           }
       }
      function callScriptMethod(url, jsonObject, action, callback, async) {

         callback = callback || function () { };
         async = (async == null || async);

         $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: url,
            data: JSON.stringify(jsonObject),
            dataType: "json",
            async: async,
            success: function (data) {

               if (data.success != "0") {
                  var getUsersUrl = '<%= Url.Action("Use_KANBAN") %>' + '?seq=' + $.trim($("#seqDT").text()) + '&biasno=' + '<%=  TireBias.Models.SessionBag.Current.biasno  %>' ;
                  window.location = getUsersUrl;
               } else alert(data.message);
            },
            error: function (xhr, status, error) {
               var err = xhr.responseText;
               alert(err.Message);
           }

         });
      }

      function GET_Barcode(obj) {
          obj.val(obj.val().toUpperCase());
          var myArray = obj.val().split('+');
         if (!(7 >= myArray.length <= 8)) {
         //   alert(1);
            return false;
         }

         var pt = $.trim(myArray[6 + (myArray.length - 7)]);

         if (pt == "A") {
            if ($.trim('<%: Model._Topcrdcd %>') != $.trim(myArray[0])) {               
               return false;
            }
         }

         if ($.trim(obj.attr("cols")) != pt) {
         //   alert(3);          
               return false;
            }
            obj.attr("chk", "T")
            return true;

         
      }

      var noMat = "";
      function Check_MAT() {
       
         myArrayA = $("#txtInputA").val().split("+");
         myArrayB = $("#txtInputB").val().split("+");
         var bln = true;
         if ($.trim(myArrayA[0]) != $.trim(myArrayB[0])) {
            noMat = "Topped Cord";
            bln = false;
            $("#dCodeA").addClass("nomat");  $("#dCodeB").addClass("nomat");
           
         } else if ($.trim(myArrayA[1]) != $.trim(myArrayB[1])) {
            noMat = "Lot " + myArrayB[1];
            bln = false;
            $("#dLotA").addClass("nomat");
            $("#dLotB").addClass("nomat");
         }
//         else if ($.trim(myArrayA[5]) != $.trim(myArrayB[5])) {
//            noMat = "Expired Date" + myArrayB[5];
//            $("#dExpA").addClass("nomat"); $("#dExpB").addClass("nomat");
//            bln = false;
//         }
//         else if ($.trim(myArrayA[2]) != $.trim(myArrayB[2])) {
//            noMat = "Rollno "+myArrayB[2];
//            $("#dRollA").addClass("nomat"); $("#dRollB").addClass("nomat");
//            bln = false;
//         }
         return bln;

      }

      $("#back").click(function () {
          var url = '<%= Url.Action("RollBack","BiasHead") %>' + '?seq=' + '<%= Model._Plandt %>' + "-" + '<%=Model._Itemno %>';
          url = url + "&st=0&biasno=" + '<%: TireBias.Models.SessionBag.Current.biasno %>' ;
          window.location = url;
      });

      $(function () {


          $("#txtInputB").focus();

          $("#txtInputA,#txtInputB").change(function () {
              noMat = "";
              if (!GET_Barcode($(this))) {
                  alert("ข้อมูลไม่ถูกต้อง");
                  $(this).removeAttr("chk");
                  $(this).val("");
                  return false;
              }


              if ($("#txtInputA").attr("chk") != "T") {
                  return;
              }
              if ($("#txtInputB").attr("chk") != "T") {
                  return;
              }

              var myArray = $(this).val().split('+');
              var Exp = false;
              if (myArray[7] == "A") {
                  $.post('<%=Url.Action("ConvertDate") %>' + '?sdate=' + myArray[4], function (data) {
                      Exp = !data.bln;
                      if (Exp) {
                          $("#dExpA").addClass("nomat");
                      }
                  }); //post
              } // if
              newtitle = "";

              Check_MAT();



              if ((noMat != "") && (Exp == true)) {
                  newtitle = 'Topped Cord A is expired and Topped Cord B don’t match Topped Cord A.';
                  $("#dialog-c").parent().find("span.ui-dialog-title").html(newtitle);
                  $("#dialog-c").dialog("open");
              } else if (Exp) {
                  newtitle = 'Topped Cord A is expired.';
                  $("#dialog-c").parent().find("span.ui-dialog-title").html(newtitle);
                  $("#dialog-c").dialog("open");
              } else if (noMat != "") {
                  newtitle = 'Topped Cord B don’t match Topped Cord A.'; 
                   $("#dialog-c").parent().find("span.ui-dialog-title").html(newtitle);
                  $("#dialog-c").dialog("open");
              }
              else Savedata();

          });

      });
         var newtitle;
         var dialog;
         $("#dialog-a").dialog({
             width: 600,
             height: 500,
             autoOpen: false,
             show: "blind",
             resizable: false, //สั่งให้ไม่สามารถย่อขยายได้
             modal: true,  //สั่งให้มีฉากเบลอๆด้านหลัง dialog
             open: function (event, ui) {
                 $(this).parent().children(".ui-widget-header").css("background", "#B22222");
                 $(this).parent().children(".ui-dialog-titlebar").css("color", "white");
                 var myArray = $("#txtInputA").val().split('+');
                 $("#dcode").text(myArray[0]);
                 $("#dLot").text(myArray[1]);
                 $("#dexp").text(myArray[4]);
                 $("#rollno").text(myArray[2]);
                 $("#dLen").text(myArray[6]);
                 $("#txtempnm").val("");
                 $("#txtpass").val("");
                 $("#txtshort").val("");
             },
             buttons: {
                 "Back": function () {
                     $("#txtInputA").val("");
                     $("#txtInputB").val("");
                     $("#txtInputA,#txtInputB").removeAttr("chk");
                     $(this).dialog("close");
                     dialog = "";
                 },
                 "Use Tire Cord": function () {
                     $(this).dialog("close");
                     dialog = "A"
                     $("#dialog-b").dialog("open");
                 }
             }
         });

      $("#dialog-c").dialog({
          width: 800,
          height: 600,
          autoOpen: false,
          resizable: false, //สั่งให้ไม่สามารถย่อขยายได้
          modal: true,  //สั่งให้มีฉากเบลอๆด้านหลัง dialog
          open: function (event, ui) {
              $(this).parent().children(".ui-widget-header").css("background", "#B22222");
              $(this).parent().children(".ui-dialog-titlebar").css("color", "white");
              var myArray = $("#txtInputA").val().split('+');
              var myArrayB = $("#txtInputB").val().split('+');
              $("#txtInputA,#txtInputB").removeAttr("chk");

              $("#hd").focus();
              $("#dCodeA").text(myArray[0]);
              $("#dLotA").text(myArray[1]);
              $("#dExpA").text(myArray[4]);
              $("#dRollA").text(myArray[2]);
              $("#txtInputB").focus();
              $(this).focus();
              $("#dCodeB").text(myArrayB[0]);
              $("#dLotB").text(myArrayB[1]);
              $("#dExpB").text(myArrayB[4]);
              $("#dRollB").text(myArrayB[2]);

              $("#txtempnm").val("");
              $("#txtpass").val("");
              $("#txtshort").val("");
          },
          buttons: {
              "Back": function (event, ui) {
                  $("#txtInputA").val("");
                  $("#txtInputB").val("");
                  $(this).dialog("close");
              },
              "Use Tire Cord": function () {
                  $(this).dialog("close");
                  dialog = "C"
                  $("#dialog-b").dialog("open");
              }
          }
      });



      function Savedata() {
         if ($("#txtInputA").val() == "") {
            return;
         }
         if ($("#txtInputB").val() == "") {
            return;
         }
         var myArrayA = $("#txtInputA").val().split("+");
         var reason = "";
       
         if ($.trim($("#txtshort").val()) != "") {
            reason = newtitle;           
         }
         var dataForSubmit = new Array();
         dataForSubmit.push({
             _biasno: '<%: TireBias.Models.SessionBag.Current.biasno %>',
            _plandt: '<%: Model._Plandt %>',
            _itemno: '<%: Model._Itemno %>',
            _Topcrdcd: '<%=Model._Topcrdcd %>',
            _Empname: '<%: User.Identity.Name %>',
            _Tcrdcd: myArrayA[0],
            _Tcrdlot: myArrayA[1],
            _topexp: myArrayA[4],
            _toplen: myArrayA[6],
            _toproll: myArrayA[2],
            _topauthemp: $("#txtempnm").val(),
            _topreatxt: reason,
            _topshtxt: $("#txtshort").val()
         });
         var getUsersUrl = '<%= Url.Action("Save_Date") %>' ;
         
         callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
      }
          

      $("#dialog-b").dialog({
         width: 650,
         height: 400,
         autoOpen: false,
         show: "blind",
         buttons: {
            "Back": function () {
               $(this).dialog("close");
            },
            "OK": function () {
            
               if ($("#txtempnm").val() == "") {
                  alert("ระบุข้อมูลไม่ครบ");
                  $("#TCLen").focus();
                  return;
               }
               if ($("#txtpass").val() == "") {
                  alert("ระบุข้อมูลไม่ครบ");
                  $("#TCLen").focus();
                  return;
               }
               if ($("#txtshort").val() == "") {
                  alert("ระบุข้อมูลไม่ครบ");
                  $("#TCLen").focus();
                  return;
               }

               $.post('<%=Url.Action("Get_Author") %>' + '?users=' + $("#txtempnm").val() + '&pass=' + $("#txtpass").val()
               , function (data) {
                  if (data.success == 0) {
                     alert(data.message);
                  }
                  else {
                     if (dialog == "A") {
                        $("#reaExp").val($("#txtshort").val());
                        Check_MAT();
                     }
                     if (dialog == "B") {
                        $("#txtreaMat").val($("#txtshort").val());
                     }

                     Savedata();
                     $("#dialog-b").dialog("close");
                  }
               });
            }
         }      

      });
   </script>
</asp:Content>
